Page({
  data: {
    date: '',
    show: false,
    shower: false,
    starttime: '12:00',
    overdate:"",
    overtime:"12:00",
    timechuo1:"",
    timechuo1:""
  },
  onLoad() {
    console.log(new Date());
    this.onConfirm({
      detail: new Date()
    })

    this.onConfirmer({
      detail: new Date()
    })

  },
  onDisplay() {
    this.setData({
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  formatDate(date) {
    date = new Date(date);
    console.log(date);
    let p = ["日", "一", "二", "三", "四", "五", "六"]
    let week = p[date.getDay()]

    this.setData({
    timechuo1:`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
    })

    return `${date.getMonth() + 1}月${date.getDate()}日周${week}`;
  },
  onConfirm(event) {
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
    });
  },


  dataselect() {
    this.setData({
      show: true
    })
  },

  overselect() {
    this.setData({
      shower: true
    })
  },

  onDisplayer() {
    this.setData({
      shower: true
    });
  },
  onCloseer() {
    this.setData({
      shower: false
    });
    console.log(11);
  },
  formatDater(date) {
    date = new Date(date);
    console.log(date);
    let p = ["日", "一", "二", "三", "四", "五", "六"]
    let week = p[date.getDay()]
    this.setData({
      timechuo2:`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
    })
    return `${date.getMonth() + 1}月${date.getDate()}日周${week}`;
  },
  onConfirmer(event) {
    this.setData({
      shower: false,
      overdate: this.formatDater(event.detail),
    });
  },

  bindTimeChanger: function (e) {
    console.log(e.detail.value)
    this.setData({
      overtime: e.detail.value
    })
  },


  bindTimeChange: function (e) {
    console.log(e.detail.value)
    this.setData({
      starttime: e.detail.value
    })
  },


  truer(){
    let time1=new Date(this.data.timechuo1+' '+this.data.starttime).getTime()

    let time2=new Date(this.data.timechuo2+' '+this.data.overtime).getTime()
    if(time1>=time2){
    wx.showToast({
      title: '请选正确时间',
      icon:"error"
    })
    }else{
      let obj={
        validStartTime:time1,
        validStartStr:this.data.date+this.data.starttime,
        validEndTime :time2,
        validEndStr:this.data.overdate+this.data.overtime
      }
    wx.setStorageSync('Date', obj)

    wx.redirectTo({
      url: '../zguye/zhuye',
    })
    }
  }

});